from jobRegistryHelper import jobRegistryHelper
from thread_scheduler.jobTriggerPoolHelper import jobTriggerPoolHelper


# 调度模块启动entry

class ExecutorBlockStrategyEnum:
    pass


class jobScheduler:

    def __init__(self):
        self.logger = None
        self.executorBizRepository = None

        # 国际化
        self._initI18n()
        # 触发器线程池
        jobTriggerPoolHelper.tostart()
        # 注册监控
        jobRegistryHelper.getInstance().start()
        # 运行失败监控
        jobFailMonitorHelper.getInstance().start()

        jobCompleteHelper.getInstance().start()
        # 日志模块
        jobLogReporterHelper.getInstance().start()
        # 调度模块启动
        jobSchedulerHelper.getInstance().start()

    def destory(self):
        # 触发器线程池
        jobTriggerPoolHelper.tostop()
        # 注册监控
        jobRegistryHelper.getInstance().tostop()
        # 运行失败监控
        jobFailMonitorHelper.getInstance().tostop()

        jobCompleteHelper.getInstance().tostop()
        # 日志模块
        jobLogReporterHelper.getInstance().tostop()
        # 调度模块启动
        jobSchedulerHelper.getInstance().tostop()

    def _initI18n(self):
        for i in ExecutorBlockStrategyEnum.values():
            i.setTile()

    # 获取执行器client, 并发执行，需要线程安全容器： 如chm
    def getExecutorBiz(self, address):
        executorBiz = self.executorBizRepository.get(address)
        return executorBiz